<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2018\10\28 0028
 * Time: 10:03
 */
namespace app\admin\controller;

use app\admin\model\Digui;
use think\Controller;
use think\Db;
use think\Request;

class Index extends Controller
{
    /**加载后台登录
     * @return mixed
     */
    public function index(Request $request)
    {
        if(!session('adminuser')){
            return redirect("/admin/index/login");
        }
        $array = Db::name('column')
            ->where('pid',0)
            ->select();
        foreach ($array as $key=>$value){
            $array[$key]['xia'] = Digui::getName('column')->digui($value['id'],0);
        }
        $this->assign('data',$array);
        $this->assign('adminuser',session('adminuser'));

        $danbiao = Db::name('model')->where('model_type','单表模型')
//            ->where('id','<>','8')
//            ->where('id','<>','9')
//            ->where('id','<>','10')
//            ->where('id','<>','11')
            ->select();
        $this->assign('danbiao',$danbiao);
        $lanbiao = Db::name('model')->where('model_type','联表模型')->select();
//        echo '<pre>';print_r($array);exit;
        $this->assign('lanbiao',$lanbiao);
        return $this->fetch();
//        echo '<pre>';print_r($array);exit;
    }

    /**加载后台首页
     * @return mixed
     */
    public function login(Request $request){
        return view('login2');
    }
    /**
     * 加载后台控制台页面
     */
    public function welcome(Request $request){
        return view('page');
    }
    public function tuichu(Request $request){
        session('adminuser',null);
        return redirect("/admin/index/index");
    }
}
